SEE: HOW TO USE THE EXPRESSION BUILDER in this file for a quick start.
***********************
I can be reached on FoxForum (Robert Pope 72030,3032) for questions.
This file describes the custom expression building facility.
The facility consists of two parts. The DATA_BLD program and the expression builder EXPRMENU.
1.DATA_BLD program.
The DATA_BLD.prg is used by the developer to create the necessary data files (DBF) if they have not been created.
Those DBF files are Q_DATA,Q_EXPR,Q_PHRASE and a file(s) to be named by the developer that contains the field lookup data for the expression builder picklist.
Q_DATA.DBF is a data dictionary that DATA_BLD builds from the current environment. Fields from the master data base and all related
data bases (directly related or indirectly related) are included. Unrelated data files are not included.
You can also build a picklist by starting DATA_BLD... Do DATA_BLD and selecting the "Create New Picklist" option.
When the DATA_BLD program is started, the developer is given a chance to re-label the data base names for use in expression picklists. This should make it easier for the user to understand what they are picking.
Example: Change label for CUST(DBF) to Customer.
The developer is given a chance to change (browse) the Field_label and the picture clause for each field used in the expression builder. Fields may also be removed from the list by deleting them. This will remove unnecessary fields or fields that would be confusing to the user.
Screen files (SCX) may be used to provide PICTURE clauses for fields and also generate code for popups from the SCX file. If the screen file has the same name as the DBF alias, then you can check the box labeled "Use field_name DBF alias as SCX file name" and DATA_BLD will look for the matching SCX file. EXAMPLE: DBF alias="FAMILY" and the screen file is "FAMILY.SCX".
If the FIELD_PICT is not empty, the picture clause in the screen file file will be ignored except when "^" is in FIELD_PICT. Logical field picture clauses will be ignored.
If the same screen file is used for all the fields in the picklist but it doesn't match the DBF alias, then you can check the box that says "Use SCX file to initialize picture clauses". Then type the name of that screen file in the "SCX file name" field.
Finally, if you have fields from several DBFs and thay are in different screen files and the screen files don't match the corresponding DBF aliases, you can type the name of the appropriate SCX file in the field
FIELD_SCX when you get into modifying the picklist (browse) and DATA_BLD
will look in those SCX files for picture and popup information.
The term "popup" may be misleading because DATA_BLD will look for Radio Buttons and array picklist as well. If it finds them it will convert that information into code that generates matching popups... used by EXPRMENU
in the form .... FIELD OPERATOR DATA, but the data will be a popup instead of a GET that the user types in.
If you use screen files to initialize the picture clauses, just modify field labels then press < F10 > to build the picklist. To see what you've done, just Do DATA_BLD and choose the "Modify Current Picklist" option.
9 SCX_FIELD Character 12 .... holds name of memvar used in
place of field name in SCX file
Not needed if memvar same as
field...Example: Field="NCAT" and
GET="m.ncat"
10 ARRAY_CODE Memo 10 .... holds code used to generate code
for array popups
DATA_BLD will attempt to genarate code for array type popups with code that takes the form.....
priv was_used
was_used=.f.
If used("LASER")
was_used=.t.
Endif
Select Distinct STUDIO ; && generates array popup for Studio field
order by STUDIO ;
from LASER ;
where !deleted() and !empty(STUDIO) ;
into array choice && array name must remain "CHOICE"
If !was_used
use in LASER
Endif
This code is stored in the ARRAY_CODE field and can be modified to suit the developers needs.
WARNING! Array name must remain "CHOICE"!
The developer may type their own SQL code in ARRAY_CODE or their own picklist choices in FIELD_MEM ( make sure the last picklist choice is
not followed by a chr(13)/< ENTER > or you will get a blank choice in the picklist.
To re-edit the Q_data data dictionary just rerun the DATA_BLD program.
DATA_BLD will continue to use the existing q_data.dbf. This allows correction of mistakes in picture clauses and field labels without
having to start over again.
NOTE: Mistakes in picture clauses is the most likely cause for the expression builder to bomb.
NOTE: When first modifying a picklist DBF (Q_DATA), you can choose "Recno()" as an option to reorder the picklist in Recno() order. However, if you have previously ordered the picklist alphabetically and written it to disk. The Recno() order option will return it to the alphabetical order since the record numbers will then correspond to the alphabetical order.
If you use the "Arrange" option, then "Recno()" will return the file to the arranged order even if the picklist file has not been written to disk.
To make a new picklist program and data file for another view/environment,
just open the new files before running the DATA_BLD program. Be sure to set the file relations and select the master/parent file. You don't have to have any DBFs open to create a picklist. Just start DATA_BLD and choose "Create New Picklist". You may initailize a new picklist with a previously created picklist. DATA_BLD will look for picklist with names that match the selected DBF and ask if you want to use them to initailize the current picklist. Example: DBF="FAMILY" and an existing picklist file = "QFAMILY". I recommend using the alias with a "Q" prefix as a naming convention for picklist.
Also, DATA_BLD will write a program file (named by the developer) that
will contain custom code for picklist menus for that particular
application environment, and create a data file (DBF) that contains
the data necessary for a picklist. The data file for the picklist will be
given the same name as the written program so the developer will know
The custom datafile will have the same structure as q_data.
One of the parameters passed to the picklist program by EXPRMENU is "data_pop". If data_pop is passed as true(.t.), the program will use code that uses DEFINE POPUP FIELD for the picklist. If you prefer to uses array style menus(i.e.... not enough open work areas), pass data_pop as false (.f.). Depending on the size of the data files in the view, you may have to increase the MVARSIZ in Config.FP. Large DBFs create large memory consuming arrays.
You can control the value of DATA_POP when you start EXPRMENU. If the fifth parameter is passed as .t.,then the picklist DBF file will be used for the field picklist. Otherwise, it will use an array stype picklist created by code in the picklist PRG. This requires more memory but uses less work areas.
The expression builder requires a minimum of 3 open workareas. It requies 2 Read Levels.
The Q_EXPR and Q_PHRASE data files contain the expression information.
Each record in q_expr contains the information for one expression. The
expression values (phrases) for one expression are contained in 1 or more
q_phrase records.
Q_EXPR and Q_PHRASE are reindexed each time you run EXPRMENU.
Of particular interest in the q_expr DBF is the field entitled "PROGRAM".
This field is used to tell the expresion builder the current environment.
It is passed as a parameter to the main program ("EXPRMENU.PRG").
Examples: my_expr=exprmenu('REPORT','QCUSTOM').
my_expr=exprmenu(PROGRAM(),'QCUSTOM').
NOTE: The 2nd parameter is the name of the custom program created by
the DATA_BLD program that contains the picklist for that
environment.
The q_expr DBF (and q_phrase.dbf) can store the expressions for an entire
application, but the "PROGRAM" field tells the expression builder which
expressions are appropriate for that particular environment and does not
show the user the other expressions.
HINT: A USER ID could be passed as the 1st parameter. This would allow
each user of the application to have their own set of selection criteria.
The parameter must be no more than 8 characters long. If there are
multiple environments in the application, then perhaps part of a USER ID
plus enough of a character string to identify the environment.
Example: USER ID="1234" Environment="Reports"
Parameter="1234_REP"
Structure for database : q_expr.dbf
Field Field Name Type Width Dec
1 EXPR_ID Character 6
2 EXPR_NAME Character 40
3 PROGRAM Character 8 && identifies environment of
&& calling program
4 FOX_EXPR Logical 1 && is it a getexpr expression
5 IG_CASE Logical 1 && ignore case for expression
6 EXPR Memo 10 && store getexpr values
** Total ** 00067
Structure for database : q_phrase.dbf
Field Field Name Type Width Dec
1 EXPR_ID Character 6
2 PHRASE_NO Numeric 2 0
3 OPERATOR Character 2
4 CONNECTOR Character 3
5 Q_FIELD Character 20
6 Q_FLABEL Character 30
7 Q_FTYPE Character 1
8 Q_FLEN Numeric 3 0
9 Q_FPICT Character 25
10 Q_FDEC Numeric 3 0
11 Q_DATA Character 120
12 QD_CHOICE Numeric 1 0
13 QM_CHOICE Numeric 1 0
14 QY_CHOICE Numeric 1 0
15 QD_EXPR Character 30
16 QM_EXPR Character 30
17 QY_EXPR Character 30
18 MATH_OP Character 1
19 MATH_DATA Character 60
20 IGNORECASE Logical 1
2.Expression builder program- EXPRMENU
** The following are some of the main procedures in the EXPRMENU program.
Expr_bld.prg- add or edit expressions
Expr_get.prg- builds complete expression from q_phrase records
Qoperate.prg- displays expression operators and returns selected
operator
Op2phra.prg- converts operator into a phrase
Example: "==" to "is the same as"
Phra2op.prg- converts phrases to operator symbols
Q_date.prg- builds variable date expression
Math.prg- adds math expression to phrase
Indexes are created for the custom picklist DBFs. They are reindexed when the particular picklist DBF is called by EXPRMENU. The reindexing code is
if file('QLASER.CDX')
delete tag all
else
INDEX ON FIELDLABEL TO TAG fieldlabel
endif
After creating a picklist file, you can open it and take a look at what is going on. Example: modify command QLASER.PRG.
HOW TO USE THE EXPRESSION BUILDER
1. Open the data files and set up the relations
2. Make sure the master data base is selected.
USE PATIENT INDEX ID
USE ADDRESS INDEX ADD_ID IN 2
SET RELATION TO ADD_ID INTO ADDRESS
GO TOP
DO DATA_BLD ...select "Build Picklist from Enviroment"
3. DATA_BLD will show the data file names ("PATIENT","ADDRESS")
and allow you to re-label them for the expression builder picklist.
4. DATA_BLD will build the data dictionary Q_DATA.DBF from all
fields in the patient and address files.
5. Then you will be able to browse q_data and change the field_labels
and picture clauses for each field if desired, and delete unwanted
fields. These changes DO NOT affect the actual data files.
6. It will then call the foxpro putfile() facility so you can name
the picklist program and data file. The default name supplied will
be the master DBF file name with a "Q" prefix. I strongly recommend using this naming convention. DATA_BLD is designed to work with it.
Example: "QPATIENT"
7. The custom picklist program and data file are created.
8. Now you are ready to insert the expression builder into your programs.
9. Be sure to look over the HELP topics when you start the exprmenu